package Chapter2.Comparing.c6;

import java.io.Serializable;
import java.util.Objects;

public class User implements Serializable {
    private String name;
    private int age;

    public User() {
    }

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return age == user.age &&
                Objects.equals(name, user.name);
    }

    /*@Override
    public int compareTo(Object o) {
        User o2 = (User) o;
        //年龄
        int num = this.age-o2.getAge();
        //按照姓名的内容
       int num2 = num == 0 ? this.name.compareTo(((User) o).name) : num;
        //按照姓名的长度
        int num3 = num2 == 0 ? this.name.length() - ((User) o).name.length() : num2;
        return num3;

    }*/

    /*@Override
    public int hashCode() {
        return Objects.hash(name, age);
    }*/
}
